package com.charmzenus.message.redis;

import java.util.concurrent.CountDownLatch;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
 
public class Receiver {

    @Autowired
    IRedisService iRedisService;

    private static final Logger LOGGER = LoggerFactory.getLogger(Receiver.class);

    private CountDownLatch latch;


    @Autowired
    public Receiver(CountDownLatch latch) {
        this.latch = latch;
    }

    public void receiveMessage(String message) {
        LOGGER.info("Received <" + message + ">");

        Object keyValue = iRedisService.getKeyValue(message);
        if (keyValue == null ){
            System.out.println("null");
            return;
        }

        System.out.println(keyValue.toString());
        latch.countDown();
    }
}